package ${package.Controller};

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.future.hair.server.config.result.CommonResult;
import com.future.hair.server.entity.${entity};
import com.future.hair.server.mapper.${table.mapperName};
import com.future.hair.server.model.PageModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**
*
* @author ${author}
* @since ${date}
* @version v1.0
*/

@RestController
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/hair/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
@Api(tags = "${entity}管理接口")

public class ${table.controllerName}{
    @Autowired
    private ${table.mapperName} mapper;

    @ApiOperation(value = "查询 ${entity} 列表")
    @RequestMapping(value = "/${table.entityPath}List", method = RequestMethod.POST)
    public CommonResult<List<${entity}>> ${table.entityPath}List(@RequestBody PageModel data,@RequestHeader String token) {
        return CommonResult.data(mapper.selectPage(new Page<>(data.getSize() , data.getCurrent()), null).getRecords());
    }

    @ApiOperation(value = "查询当前 ${entity}")
    @RequestMapping(value = "/${table.entityPath}Id", method = RequestMethod.POST)
    public CommonResult<${entity}> ${table.entityPath}Id(@RequestBody ${entity} data,@RequestHeader String token) {
        return CommonResult.data(mapper.selectById(data.getId()));
    }

    @ApiOperation(value = "增加 ${entity}")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public CommonResult<Integer> create(@RequestBody ${entity} data,@RequestHeader String token) {
        Integer result = mapper.insert(data);
        if (result == 1){
            return CommonResult.data(result);
        }else {
            return CommonResult.failed("创建失败");
        }
    }

    @ApiOperation(value = "更新 ${entity}")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<Integer> update(@RequestBody ${entity} data, @RequestHeader String token) {
        Integer result = mapper.updateById(data);
        if (result==1){
            return CommonResult.data(result);
        }else {
            return CommonResult.failed("更新失败");
        }
    }

    @ApiOperation(value = "删除 ${entity}")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public CommonResult<Integer> delete(@RequestBody ${entity} data,@RequestHeader String token) {
        Integer result = mapper.deleteById(data.getId());
        if (result==1){
            return CommonResult.data(result);
        }else {
            return CommonResult.failed("删除失败");
        }
    }
}